<template>
  <!-- 放置标题图片 @是设置的别名-->
  <div class="login">
    <div class="box">
      <el-form ref="form" :model="form" :rules="rules">
        <el-form-item>
          <img src="@/assets/common/login-logo.png" alt="">
        </el-form-item>
        <el-form-item prop="mobile">
          <el-input
            v-model="form.mobile"
            prefix-icon="el-icon-user-solid"
            placeholder="请输入内容"
            @keydown.enter.native="btn"
          />
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="form.password"
            prefix-icon="el-icon-user-solid"
            placeholder="请输入内容"
            type="password"
            @keydown.enter.native="btn"
          />
        </el-form-item>
        <el-form-item> <el-button @click="btn">登录</el-button></el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
// import { toLogin } from '@/api/login.js'
export default {
  name: '',
  data() {
    return {
      form: {
        mobile: '13800000002',
        password: '123456'
      },
      rules: {
        mobile: [
          { required: true, message: '必填项', trigger: 'blur' },
          {
            validator: (rule, value, callback) => {
              var reg =
                /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57])[0-9]{8}$/
              if (reg.test(value)) {
                callback()
              } else {
                callback(new Error('验证失败'))
              }
            },
            trigger: 'blur'
          }
        ],
        password: [
          { required: true, message: '必填项', trigger: 'blur' },
          { min: 6, max: 12, message: '长度需要在6-12位', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {},
  created() {},
  methods: {
    btn() {
      this.$refs.form.validate(async(res) => {
        if (res) {
          // const res = await sysLogin(this.form)
          // console.log(res)
          // this.$message('验证成功')
          await this.$store.dispatch('user/toLogin', this.form)
          const _redirect = this.$route.query.redirect || '/'
          this.$router.push(_redirect)
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.login {
  width: 100%;
  height: 100%;
  background: url('../../assets/common/login.jpg') no-repeat; // 设置背景图片
  background-position: center; // 将图片位置设置为充满整个屏幕
  display: flex;
  justify-content: center;
  align-items: center;
  .el-form-item {
    border: 0.0625rem solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.7); // 输入登录表单的背景色
    border-radius: 0.3125rem;
    color: #454545;
  }
  .el-button {
    background: #407ffe;
    height: 4rem;
    width: 100%;
    line-height: 2rem;
    font-size: 1.5rem;
  }
}
</style>
